/*
 * $Id: object-weapon.cpp 315 2010-03-25 23:57:03Z cmtonkinson@gmail.com $
 *
 * This file is part of the Symphony project <http://code.google.com/p/symphonymud/>
 * Copyright 2005-2010 Chris Tonkinson <cmtonkinson@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "object-weapon.h"
#include "regex.h"

ObjWeapon::ObjWeapon( void ):
    _type( 0 ),
    _verb( 0 ) {
  return;
}

ObjWeapon::ObjWeapon( const ObjWeapon& ref ):
    _type( ref.type() ),
    _verb( ref.verb() ),
    _damage( ref.damage() ) {
  return;
}

ObjWeapon::ObjWeapon( ROW row ) {
  type( row["weapon_type"] );
  verb( row["weapon_verb"] );
  damage().number( row["weapon_damage_number"] );
  damage().faces( row["weapon_damage_faces"] );
  return;
}

ObjWeapon::~ObjWeapon( void ) {
  return;
}

const char* ObjWeapon::typeToString( void ) const {
  switch ( type() ) {
    case Type_Axe:        return "axe";
    case Type_Club:       return "club";
    case Type_Dagger:     return "dagger";
    case Type_Flail:      return "flail";
    case Type_Gauntlet:   return "gauntlet";
    case Type_Longsword:  return "longsword";
    case Type_Mace:       return "mace";
    case Type_Polearm:    return "polearm";
    case Type_Shortsword: return "shortsword";
    case Type_Staff:      return "staff";
    case Type_Whip:       return "whip";
    default:              return "undefined";
  }
}

void ObjWeapon::stringToType( const std::string& src ) {
  if ( Regex::strPrefix( src, "axe" ) ) {
    type( Type_Axe );
  } else if ( Regex::strPrefix( src, "club" ) ) {
    type( Type_Club );
  } else if ( Regex::strPrefix( src, "dagger" ) ) {
    type( Type_Dagger );
  } else if ( Regex::strPrefix( src, "flail" ) ) {
    type( Type_Flail );
  } else if ( Regex::strPrefix( src, "gauntlet" ) ) {
    type( Type_Gauntlet );
  } else if ( Regex::strPrefix( src, "longsword" ) ) {
    type( Type_Longsword );
  } else if ( Regex::strPrefix( src, "mace" ) ) {
    type( Type_Mace );
  } else if ( Regex::strPrefix( src, "polearm" ) ) {
    type( Type_Polearm );
  } else if ( Regex::strPrefix( src, "shortsword" ) ) {
    type( Type_Shortsword );
  } else if ( Regex::strPrefix( src, "staff" ) ) {
    type( Type_Staff );
  } else if ( Regex::strPrefix( src, "whip" ) ) {
    type( Type_Whip );
  } else {
    type( Type_Undefined );
  }
  return;
}

const char* ObjWeapon::verbToString( void ) const {
  switch ( verb() ) {
    // bash
    case Verb_Bash:     return "bash";
    case Verb_Beating:  return "beating";
    case Verb_Crush:    return "crush";
    case Verb_Pound:    return "pound";
    case Verb_Punch:    return "punch";
    case Verb_Slam:     return "slam";
    case Verb_Smash:    return "smash";
    case Verb_Strike:   return "strike";
    case Verb_Thwack:   return "thwack";
    // slash
    case Verb_Chop:     return "chop";
    case Verb_Cleave:   return "cleave";
    case Verb_Cut:      return "cut";
    case Verb_Hack:     return "hack";
    case Verb_Slash:    return "slash";
    case Verb_Slice:    return "slice";
    // pierce
    case Verb_Pierce:   return "pierce";
    case Verb_Prick:    return "prick";
    case Verb_Puncture: return "puncture";
    case Verb_Stab:     return "stab";
    case Verb_Sting:    return "sting";
    case Verb_Thrust:   return "thrust";
    // exotic
    case Verb_Wrath:    return "wrath";
    default:            return "undefined";
  }
}

void ObjWeapon::stringToVerb( const std::string& src ) {
  // bash
  if ( Regex::strPrefix( src, "bash" ) ) {
    type( Verb_Bash );
  } else if ( Regex::strPrefix( src, "beating" ) ) {
    type( Verb_Beating );
  } else if ( Regex::strPrefix( src, "crush" ) ) {
    type( Verb_Crush );
  } else if ( Regex::strPrefix( src, "pound" ) ) {
    type( Verb_Pound );
  } else if ( Regex::strPrefix( src, "punch" ) ) {
    type( Verb_Punch );
  } else if ( Regex::strPrefix( src, "slam" ) ) {
    type( Verb_Slam );
  } else if ( Regex::strPrefix( src, "smash" ) ) {
    type( Verb_Smash );
  } else if ( Regex::strPrefix( src, "strike" ) ) {
    type( Verb_Strike );
  } else if ( Regex::strPrefix( src, "thwack" ) ) {
    type( Verb_Thwack );
  // slash
  } else if ( Regex::strPrefix( src, "chop" ) ) {
    type( Verb_Chop );
  } else if ( Regex::strPrefix( src, "cleave" ) ) {
    type( Verb_Cleave );
  } else if ( Regex::strPrefix( src, "cut" ) ) {
    type( Verb_Cut );
  } else if ( Regex::strPrefix( src, "hack" ) ) {
    type( Verb_Hack );
  } else if ( Regex::strPrefix( src, "slash" ) ) {
    type( Verb_Slash );
  } else if ( Regex::strPrefix( src, "slice" ) ) {
    type( Verb_Slice );
  // pierce
  } else if ( Regex::strPrefix( src, "pierce" ) ) {
    type( Verb_Pierce );
  } else if ( Regex::strPrefix( src, "prick" ) ) {
    type( Verb_Prick );
  } else if ( Regex::strPrefix( src, "puncture" ) ) {
    type( Verb_Puncture );
  } else if ( Regex::strPrefix( src, "stab" ) ) {
    type( Verb_Stab );
  } else if ( Regex::strPrefix( src, "sting" ) ) {
    type( Verb_Sting );
  } else if ( Regex::strPrefix( src, "thrust" ) ) {
    type( Verb_Thrust );
  // exotic
  } else if ( Regex::strPrefix( src, "wrath" ) ) {
    type( Verb_Wrath );
  } else {
    type( Verb_Undefined );
  }
  return;
}
